package visualizer.drawable.transition;

import processing.core.PGraphics;
import visualizer.drawable.AbstractDrawable;
import visualizer.drawable.Drawable;

public abstract class AbstractTransition extends AbstractDrawable {
	private Drawable from;
	private Drawable to;
	private int steps;
	private int currentStep;
	
	public AbstractTransition(Drawable from, Drawable to, int steps)
	{
		this.from = from;
		this.to = to;
		this.steps = steps;
		
		if (steps < 0) {
			throw new RuntimeException("Amount of steps can't be negative");
		}
	}
	
	public Drawable getFrom()
	{
		return from;
	}
	
	public Drawable getTo()
	{
		return to;
	}
	
	public int getSteps()
	{
		return steps;
	}
	
	public int getCurrentStep()
	{
		return currentStep;
	}
	
	protected AbstractTransition incrementStep()
	{
		if (!isDone()) {
			this.currentStep++;
		}
		return this;
	}
	
	public boolean isDone()
	{
		return currentStep == steps;
	}
	
	public void draw(PGraphics g)
	{
		if (!isDone()) {
			drawFrom(g);
			incrementStep();
		}
		drawTo(g);
	}
	
	public double getCompletionPercentage()
	{
		return ((double) currentStep) / ((double) steps);
	}
	
	public abstract void drawFrom(PGraphics g);
	public abstract void drawTo(PGraphics g);
}
